package top.lyc829.iot_android.adapter;

import android.widget.Button;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

import org.jetbrains.annotations.NotNull;

import top.lyc829.iot_android.MyApp;
import top.lyc829.iot_android.R;
import top.lyc829.iot_android.entity.Log;

/**
 * @Author lyc
 * @create 2021-06-18 19:57
 */
public class LogAdapter extends BaseQuickAdapter<Log, BaseViewHolder> {

    public LogAdapter() {
        super(R.layout.log_item);
    }

    @Override
    protected void convert(@NotNull BaseViewHolder baseViewHolder, Log log) {
        baseViewHolder.setText(R.id.tv_user_name, log.getUsername());
        String type = (log.getType() < 3 && log.getType() >= 0) ? MyApp.getContext().getResources().getStringArray(R.array.type)[log.getType()] : "未知";
        baseViewHolder.setText(R.id.tv_type, type);
        baseViewHolder.setText(R.id.tv_time, log.getTime());

        Button button = baseViewHolder.getView(R.id.btn_state);

        if (log.getState().equals(1)) {
            button.setText("成功");
            button.setTextColor(MyApp.getContext().getResources().getColor(R.color.white, null));
            button.setBackgroundResource(R.drawable.shape_btn_blue);
        } else {
            button.setText("失败");
            button.setTextColor(MyApp.getContext().getResources().getColor(R.color.red_delete, null));
            button.setBackgroundResource(R.drawable.shape_btn_gray);
        }

    }
}
